package com.situ.springbootscientific.controller;

import com.situ.springbootscientific.pojo.Admin;
import com.situ.springbootscientific.service.IAdminService;
import com.situ.springbootscientific.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/admin")
public class AdminController {
    @Autowired
    IAdminService adminService;
    @PostMapping("/login")
    public Result login(@RequestBody Admin admin) {
        //暂时没写token Token has not been written temporarily
        System.out.println("AdminController.login");
        //First check whether the account password is empty
        //no,no,The front end will verify this,Just query directly.
        //写查询语句,不对,必须得写token,不然就得用session
        Admin logeinAdmin = adminService.login(admin);
        if (ObjectUtils.isEmpty(logeinAdmin.getName())||ObjectUtils.isEmpty(logeinAdmin.getPassword())) {
            return Result.error("wrong username or password");
        }
        //successful login
        return Result.ok("successful login", logeinAdmin);
    }
}
